package com.wxxymaker.edu.controller.view;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.PathParam;
import com.blade.mvc.annotation.Route;
import com.blade.mvc.http.Request;
import com.wxxymaker.edu.model.entity.User;
import com.wxxymaker.edu.roles.StudentRoles;
import com.wxxymaker.edu.service.CourseService;
import com.wxxymaker.edu.utils.TokenUtils;

/**
 * @AUTHOR soft
 * @DATE 2018/9/1 22:40
 * @DESCRIBE 题目控制器
 */
@StudentRoles
@Path("/practice")
public class PracticeViewHandler {

    @Inject
    private CourseService courseService;

    /**
     * 查看题目
     * @param id 题目id
     */
    @Route("/:kid/look/:id")
    public String look(Request request,
                       @PathParam int kid,
                       @PathParam int id) {
        User user = TokenUtils.currentUser();
        if (courseService.isMyPublish(kid, user.getId())) {
            //是否在模态框中查看，0不是，1是(能直接查看答案和解析)
            request.attribute("modal", 1);
        } else request.attribute("modal", 0);
        request.attribute("preId", id);
        return render("itemPractice");
    }


    private String render(String view) {
        return "course/set/" + view;
    }
}
